package com.exam.demo.service.impl;

import com.exam.demo.mapper.AnswerMapper;
import com.exam.demo.mapper.ProblemMapper;
import com.exam.demo.mapper.TestMapper;
import com.exam.demo.pojo.Test;
import com.exam.demo.pojo.TestExample;
import com.exam.demo.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ExamImpl implements ExamService {
    @Autowired
    private AnswerMapper answerMapper;

    @Autowired
    private ProblemMapper problemMapper;

    @Autowired
    private TestMapper testMapper;

    @Override
    public int addTest(Test test) {
        return testMapper.insert(test);
    }

    @Override
    public int deleteTest(int tstNo) {
        return testMapper.deleteByPrimaryKey(tstNo);
    }

    @Override
    public int editTest(Test test) {
        return testMapper.updateByPrimaryKeySelective(test);
    }

    @Override
    public Test queryTest(int tstNo) {
        return testMapper.selectByPrimaryKey(tstNo);
    }

    @Override
    public List<Test> queryTestByName(String name) {
        TestExample testExample = new TestExample();
        TestExample.Criteria criteria = testExample.createCriteria();
        criteria.andTstNameLike(name);

        return testMapper.selectByExample(testExample);
    }

    @Override
    public List<Test> queryTestByDif(String dif) {
        TestExample testExample = new TestExample();
        TestExample.Criteria criteria = testExample.createCriteria();
        criteria.andTstDifLike(dif);

        return testMapper.selectByExample(testExample);
    }

    @Override
    public List<Test> queryTestByType(String type) {
        TestExample testExample = new TestExample();
        TestExample.Criteria criteria = testExample.createCriteria();
        criteria.andTstTypeLike(type);

        return testMapper.selectByExample(testExample);
    }

    @Override
    public List<Test> queryTestByTime(Date date1, Date date2) {
        TestExample testExample = new TestExample();
        TestExample.Criteria criteria = testExample.createCriteria();
        criteria.andTstTimeBetween(date1,date2);

        return testMapper.selectByExample(testExample);
    }

    @Override
    public List<Test> queryAllTest() {
        TestExample testExample = new TestExample();
        TestExample.Criteria criteria = testExample.createCriteria();
        criteria.andTstNoIsNotNull();
        return testMapper.selectByExample(testExample);
    }
}
